package nc.ui.so.m32.billui.pub;

import java.util.Iterator;
import java.util.List;

import javax.swing.Action;

import nc.funcnode.ui.action.MenuAction;
import nc.ui.pub.bill.BillCardPanel;
import nc.ui.pub.bill.BillListPanel;
import nc.ui.so.m32.billui.action.FindPriceCondition;
import nc.ui.so.pub.keyvalue.ListKeyValue;
import nc.ui.uif2.actions.StandAloneToftPanelActionContainer;
import nc.vo.so.m32.entity.SaleInvoiceHVO;

public class UptFindPriCondActionEnable {
	public void uptListOfAction(int rownum, BillListPanel billListPanel,
			StandAloneToftPanelActionContainer actionsOfList) {
		ListKeyValue keyValue = new ListKeyValue(billListPanel,
				nc.vo.so.pub.enumeration.ListTemplateType.MAIN);

		String str_ntotalorigsubmny = keyValue.getBodyStringValue(rownum,
				SaleInvoiceHVO.NTOTALORIGSUBMNY);
		
		uptEnable(actionsOfList,str_ntotalorigsubmny);
	}

	public void uptCardOfAction(BillCardPanel billCardPanel,
			StandAloneToftPanelActionContainer actionsOfCard) {
		
		String str_ntotalorigsubmny = billCardPanel
		.getHeadItem(SaleInvoiceHVO.NTOTALORIGSUBMNY)
		.getValueObject().toString();

		uptEnable(actionsOfCard, str_ntotalorigsubmny);
	}

	private void uptEnable(StandAloneToftPanelActionContainer actionsOF,
			String str_ntotalorigsubmny) {
		List<Action> actionList = actionsOF.getActions();

		for (Iterator<Action> iter = actionList.iterator(); iter.hasNext();) {
			Action action = iter.next();

			if (MenuAction.class.getName().equals(action.getClass().getName())) {
				MenuAction menuAction = (MenuAction) action;

				Action[] childActions = menuAction.getAllChild();

				for (int i = 0; i < childActions.length; i++) {
					Action childAction = childActions[i];

					if (FindPriceCondition.class.getName().equals(
							childAction.getClass().getName())) {
						if (str_ntotalorigsubmny != null
								&& !str_ntotalorigsubmny.equals("")) {
							Double ntotalorigsubmny = Double
									.parseDouble(str_ntotalorigsubmny);

							if (ntotalorigsubmny != 0) {
								childAction.setEnabled(false);
							} else {
								childAction.setEnabled(true);
							}
						} else {
							childAction.setEnabled(true);
						}
					}
				}
			}
		}
	}
}
